<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<title>Ruby on Rails 4.0 Release Notes — Ruby on Rails Guides</title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />

<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />

<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />

<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
</head>
<body class="guide">
  <div id="topNav">
    <div class="wrapper">
      <strong class="more-info-label">更多内容 <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
      <span class="red-button more-info-button">
        更多内容
      </span>
      <ul class="more-info-links s-hidden">
        <li class="more-info"><a href="http://weblog.rubyonrails.org/">博客</a></li>
        <li class="more-info"><a href="http://guides.rubyonrails.org/">指南</a></li>
        <li class="more-info"><a href="http://api.rubyonrails.org/">API</a></li>
        <li class="more-info"><a href="http://stackoverflow.com/questions/tagged/ruby-on-rails">提问</a></li>
        <li class="more-info"><a href="https://github.com/rails/rails">到 GitHub 贡献</a></li>
        <li class="more-info"><a href="https://ruby-china.org/">Ruby China 社区</a></li>
      </ul>
    </div>
  </div>
  <div id="header">
    <div class="wrapper clearfix">
      <h1><a href="index.html" title="返回首页">Rails 指南</a></h1>
      <ul class="nav">
        <li><a class="nav-item" href="index.html">首页</a></li>
        <li class="guides-index guides-index-large">
          <a href="index.html" id="guidesMenu" class="guides-index-item nav-item">指南索引</a>
          <div id="guides" class="clearfix" style="display: none;">
            <hr />
              <dl class="L">
                <dt>新手入门</dt>
                <dd><a href="getting_started.html">Rails 入门</a></dd>
                <dt>模型</dt>
                <dd><a href="active_record_basics.html">Active Record 基础</a></dd>
                <dd><a href="active_record_migrations.html">Active Record 迁移</a></dd>
                <dd><a href="active_record_validations.html">Active Record 数据验证</a></dd>
                <dd><a href="active_record_callbacks.html">Active Record 回调</a></dd>
                <dd><a href="association_basics.html">Active Record 关联</a></dd>
                <dd><a href="active_record_querying.html">Active Record 查询接口</a></dd>
                <dt>视图</dt>
                <dd><a href="layouts_and_rendering.html">Rails 布局和视图渲染</a></dd>
                <dd><a href="form_helpers.html">Action View 表单辅助方法</a></dd>
                <dt>控制器</dt>
                <dd><a href="action_controller_overview.html">Action Controller 概览</a></dd>
                <dd><a href="routing.html">Rails 路由全解</a></dd>
              </dl>
              <dl class="R">
                <dt>深入探索</dt>
                <dd><a href="active_support_core_extensions.html">Active Support 核心扩展</a></dd>
                <dd><a href="i18n.html">Rails 国际化 API</a></dd>
                <dd><a href="action_mailer_basics.html">Action Mailer 基础</a></dd>
                <dd><a href="active_job_basics.html">Active Job 基础</a></dd>
                <dd><a href="testing.html">Rails 应用测试指南</a></dd>
                <dd><a href="security.html">Ruby on Rails 安全指南</a></dd>
                <dd><a href="debugging_rails_applications.html">调试 Rails 应用</a></dd>
                <dd><a href="configuring.html">配置 Rails 应用</a></dd>
                <dd><a href="command_line.html">Rails 命令行</a></dd>
                <dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
                <dd><a href="working_with_javascript_in_rails.html">在 Rails 中使用 JavaScript</a></dd>
                <dd><a href="autoloading_and_reloading_constants.html">自动加载和重新加载常量</a></dd>
                <dd><a href="caching_with_rails.html">Rails 缓存概览</a></dd>
                <dd><a href="api_app.html">使用 Rails 开发只提供 API 的应用</a></dd>
                <dd><a href="action_cable_overview.html">Action Cable 概览</a></dd>
                <dt>扩展 Rails</dt>
                <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
                <dd><a href="generators.html">创建及定制 Rails 生成器和模板</a></dd>
                <dt>为 Ruby on Rails 做贡献</dt>
                <dd><a href="contributing_to_ruby_on_rails.html">为 Ruby on Rails 做贡献</a></dd>
                <dd><a href="api_documentation_guidelines.html">API 文档指导方针</a></dd>
                <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails 指南指导方针</a></dd>
                <dt>维护方针</dt>
                <dd><a href="maintenance_policy.html">Ruby on Rails 的维护方针</a></dd>
                <dt>发布记</dt>
                <dd><a href="upgrading_ruby_on_rails.html">Ruby on Rails 升级指南</a></dd>
                <dd><a href="5_0_release_notes.html">Ruby on Rails 5.0 发布记</a></dd>
                <dd><a href="4_2_release_notes.html">Ruby on Rails 4.2 发布记</a></dd>
                <dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 发布记</a></dd>
                <dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 发布记</a></dd>
                <dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 发布记</a></dd>
                <dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 发布记</a></dd>
                <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 发布记</a></dd>
                <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 发布记</a></dd>
                <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 发布记</a></dd>
              </dl>
          </div>
        </li>
        <li><a class="nav-item" href="contributing_to_ruby_on_rails.html">贡献</a></li>
        <li><a class="nav-item" href="credits.html">感谢</a></li>
        <li class="guides-index guides-index-small">
          <select class="guides-index-item nav-item">
            <option value="index.html">指南索引</option>
              <optgroup label="新手入门">
                  <option value="getting_started.html">Rails 入门</option>
              </optgroup>
              <optgroup label="模型">
                  <option value="active_record_basics.html">Active Record 基础</option>
                  <option value="active_record_migrations.html">Active Record 迁移</option>
                  <option value="active_record_validations.html">Active Record 数据验证</option>
                  <option value="active_record_callbacks.html">Active Record 回调</option>
                  <option value="association_basics.html">Active Record 关联</option>
                  <option value="active_record_querying.html">Active Record 查询接口</option>
              </optgroup>
              <optgroup label="视图">
                  <option value="layouts_and_rendering.html">Rails 布局和视图渲染</option>
                  <option value="form_helpers.html">Action View 表单辅助方法</option>
              </optgroup>
              <optgroup label="控制器">
                  <option value="action_controller_overview.html">Action Controller 概览</option>
                  <option value="routing.html">Rails 路由全解</option>
              </optgroup>
              <optgroup label="深入探索">
                  <option value="active_support_core_extensions.html">Active Support 核心扩展</option>
                  <option value="i18n.html">Rails 国际化 API</option>
                  <option value="action_mailer_basics.html">Action Mailer 基础</option>
                  <option value="active_job_basics.html">Active Job 基础</option>
                  <option value="testing.html">Rails 应用测试指南</option>
                  <option value="security.html">Ruby on Rails 安全指南</option>
                  <option value="debugging_rails_applications.html">调试 Rails 应用</option>
                  <option value="configuring.html">配置 Rails 应用</option>
                  <option value="command_line.html">Rails 命令行</option>
                  <option value="asset_pipeline.html">Asset Pipeline</option>
                  <option value="working_with_javascript_in_rails.html">在 Rails 中使用 JavaScript</option>
                  <option value="autoloading_and_reloading_constants.html">自动加载和重新加载常量</option>
                  <option value="caching_with_rails.html">Rails 缓存概览</option>
                  <option value="api_app.html">使用 Rails 开发只提供 API 的应用</option>
                  <option value="action_cable_overview.html">Action Cable 概览</option>
              </optgroup>
              <optgroup label="扩展 Rails">
                  <option value="rails_on_rack.html">Rails on Rack</option>
                  <option value="generators.html">创建及定制 Rails 生成器和模板</option>
              </optgroup>
              <optgroup label="为 Ruby on Rails 做贡献">
                  <option value="contributing_to_ruby_on_rails.html">为 Ruby on Rails 做贡献</option>
                  <option value="api_documentation_guidelines.html">API 文档指导方针</option>
                  <option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails 指南指导方针</option>
              </optgroup>
              <optgroup label="维护方针">
                  <option value="maintenance_policy.html">Ruby on Rails 的维护方针</option>
              </optgroup>
              <optgroup label="发布记">
                  <option value="upgrading_ruby_on_rails.html">Ruby on Rails 升级指南</option>
                  <option value="5_0_release_notes.html">Ruby on Rails 5.0 发布记</option>
                  <option value="4_2_release_notes.html">Ruby on Rails 4.2 发布记</option>
                  <option value="4_1_release_notes.html">Ruby on Rails 4.1 发布记</option>
                  <option value="4_0_release_notes.html">Ruby on Rails 4.0 发布记</option>
                  <option value="3_2_release_notes.html">Ruby on Rails 3.2 发布记</option>
                  <option value="3_1_release_notes.html">Ruby on Rails 3.1 发布记</option>
                  <option value="3_0_release_notes.html">Ruby on Rails 3.0 发布记</option>
                  <option value="2_3_release_notes.html">Ruby on Rails 2.3 发布记</option>
                  <option value="2_2_release_notes.html">Ruby on Rails 2.2 发布记</option>
              </optgroup>
          </select>
        </li>
      </ul>
    </div>
  </div>
  <hr class="hide" />

  <div id="feature">
    <div class="wrapper">
      <h2>Ruby on Rails 4.0 Release Notes</h2><p>Highlights in Rails 4.0:</p>
<ul>
<li>Ruby 2.0 preferred; 1.9.3+ required</li>
<li>Strong Parameters</li>
<li>Turbolinks</li>
<li>Russian Doll Caching</li>
</ul>
<p>These release notes cover only the major changes. To learn about various bug
fixes and changes, please refer to the change logs or check out the <a href="https://github.com/rails/rails/commits/4-0-stable">list of
commits</a> in the main Rails
repository on GitHub.</p>

              <div id="subCol">
          <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />目录</h3>
          <ol class="chapters">
<li><a href="#upgrading-to-rails-4-0">Upgrading to Rails 4.0</a></li>
<li>
<a href="#creating-a-rails-4-0-application">Creating a Rails 4.0 application</a>

<ul>
<li><a href="#vendoring-gems">Vendoring Gems</a></li>
<li><a href="#living-on-the-edge">Living on the Edge</a></li>
</ul>
</li>
<li>
<a href="#major-features">Major Features</a>

<ul>
<li><a href="#upgrade">Upgrade</a></li>
<li><a href="#actionpack">ActionPack</a></li>
<li><a href="#general">General</a></li>
<li><a href="#security">Security</a></li>
</ul>
</li>
<li><a href="#extraction-of-features-to-gems">Extraction of features to gems</a></li>
<li><a href="#documentation">Documentation</a></li>
<li>
<a href="#railties">Railties</a>

<ul>
<li><a href="#railties-notable-changes">Notable changes</a></li>
<li><a href="#railties-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#action-mailer">Action Mailer</a>

<ul>
<li><a href="#action-mailer-notable-changes">Notable changes</a></li>
<li><a href="#action-mailer-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#active-model">Active Model</a>

<ul>
<li><a href="#active-model-notable-changes">Notable changes</a></li>
<li><a href="#active-model-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#active-support">Active Support</a>

<ul>
<li><a href="#active-support-notable-changes">Notable changes</a></li>
<li><a href="#active-support-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#action-pack">Action Pack</a>

<ul>
<li><a href="#action-pack-notable-changes">Notable changes</a></li>
<li><a href="#action-pack-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#active-record">Active Record</a>

<ul>
<li><a href="#active-record-notable-changes">Notable changes</a></li>
<li><a href="#active-record-deprecations">Deprecations</a></li>
</ul>
</li>
<li><a href="#credits">Credits</a></li>
</ol>

        </div>

    </div>
  </div>

  <div id="container">
    <div class="wrapper">
      <div id="mainCol">
        <h3 id="upgrading-to-rails-4-0">1 Upgrading to Rails 4.0</h3><p>If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3.2 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 4.0. A list of things to watch out for when upgrading is available in the <a href="upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0">Upgrading Ruby on Rails</a> guide.</p><h3 id="creating-a-rails-4-0-application">2 Creating a Rails 4.0 application</h3><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
 You should have the 'rails' RubyGem installed
$ rails new myapp
$ cd myapp

</pre>
</div>
<h4 id="vendoring-gems">2.1 Vendoring Gems</h4><p>Rails now uses a <code>Gemfile</code> in the application root to determine the gems you require for your application to start. This <code>Gemfile</code> is processed by the <a href="https://github.com/carlhuda/bundler">Bundler</a> gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.</p><p>More information: <a href="http://bundler.io">Bundler homepage</a></p><h4 id="living-on-the-edge">2.2 Living on the Edge</h4><p><code>Bundler</code> and <code>Gemfile</code> makes freezing your Rails application easy as pie with the new dedicated <code>bundle</code> command. If you want to bundle straight from the Git repository, you can pass the <code>--edge</code> flag:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
$ rails new myapp --edge

</pre>
</div>
<p>If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the <code>--dev</code> flag:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
$ ruby /path/to/rails/railties/bin/rails new myapp --dev

</pre>
</div>
<h3 id="major-features">3 Major Features</h3><p><a href="http://guides.rubyonrails.org/images/rails4_features.png"><img src="images/rails4_features.png" alt="Rails 4.0"></a></p><h4 id="upgrade">3.1 Upgrade</h4>
<ul>
<li>
<strong>Ruby 1.9.3</strong> (<a href="https://github.com/rails/rails/commit/a0380e808d3dbd2462df17f5d3b7fcd8bd812496">commit</a>) - Ruby 2.0 preferred; 1.9.3+ required</li>
<li>
<strong><a href="http://www.youtube.com/watch?v=z6YgD6tVPQs">New deprecation policy</a></strong> - Deprecated features are warnings in Rails 4.0 and will be removed in Rails 4.1.</li>
<li>
<strong>ActionPack page and action caching</strong> (<a href="https://github.com/rails/rails/commit/b0a7068564f0c95e7ef28fc39d0335ed17d93e90">commit</a>) - Page and action caching are extracted to a separate gem. Page and action caching requires too much manual intervention (manually expiring caches when the underlying model objects are updated). Instead, use Russian doll caching.</li>
<li>
<strong>ActiveRecord observers</strong> (<a href="https://github.com/rails/rails/commit/ccecab3ba950a288b61a516bf9b6962e384aae0b">commit</a>) - Observers are extracted to a separate gem. Observers are only needed for page and action caching, and can lead to spaghetti code.</li>
<li>
<strong>ActiveRecord session store</strong> (<a href="https://github.com/rails/rails/commit/0ffe19056c8e8b2f9ae9d487b896cad2ce9387ad">commit</a>) - The ActiveRecord session store is extracted to a separate gem. Storing sessions in SQL is costly. Instead, use cookie sessions, memcache sessions, or a custom session store.</li>
<li>
<strong>ActiveModel mass assignment protection</strong> (<a href="https://github.com/rails/rails/commit/f8c9a4d3e88181cee644f91e1342bfe896ca64c6">commit</a>) - Rails 3 mass assignment protection is deprecated. Instead, use strong parameters.</li>
<li>
<strong>ActiveResource</strong> (<a href="https://github.com/rails/rails/commit/f1637bf2bb00490203503fbd943b73406e043d1d">commit</a>) - ActiveResource is extracted to a separate gem. ActiveResource was not widely used.</li>
<li>
<strong>vendor/plugins removed</strong> (<a href="https://github.com/rails/rails/commit/853de2bd9ac572735fa6cf59fcf827e485a231c3">commit</a>) - Use a Gemfile to manage installed gems.</li>
</ul>
<h4 id="actionpack">3.2 ActionPack</h4>
<ul>
<li>
<strong>Strong parameters</strong> (<a href="https://github.com/rails/rails/commit/a8f6d5c6450a7fe058348a7f10a908352bb6c7fc">commit</a>) - Only allow whitelisted parameters to update model objects (<code>params.permit(:title, :text)</code>).</li>
<li>
<strong>Routing concerns</strong> (<a href="https://github.com/rails/rails/commit/0dd24728a088fcb4ae616bb5d62734aca5276b1b">commit</a>) - In the routing DSL, factor out common subroutes (<code>comments</code> from <code>/posts/1/comments</code> and <code>/videos/1/comments</code>).</li>
<li>
<strong>ActionController::Live</strong> (<a href="https://github.com/rails/rails/commit/af0a9f9eefaee3a8120cfd8d05cbc431af376da3">commit</a>) - Stream JSON with <code>response.stream</code>.</li>
<li>
<strong>Declarative ETags</strong> (<a href="https://github.com/rails/rails/commit/ed5c938fa36995f06d4917d9543ba78ed506bb8d">commit</a>) - Add controller-level etag additions that will be part of the action etag computation.</li>
<li>
<strong><a href="http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works">Russian doll caching</a></strong> (<a href="https://github.com/rails/rails/commit/4154bf012d2bec2aae79e4a49aa94a70d3e91d49">commit</a>) - Cache nested fragments of views. Each fragment expires based on a set of dependencies (a cache key). The cache key is usually a template version number and a model object.</li>
<li>
<strong>Turbolinks</strong> (<a href="https://github.com/rails/rails/commit/e35d8b18d0649c0ecc58f6b73df6b3c8d0c6bb74">commit</a>) - Serve only one initial HTML page. When the user navigates to another page, use pushState to update the URL and use AJAX to update the title and body.</li>
<li>
<strong>Decouple ActionView from ActionController</strong> (<a href="https://github.com/rails/rails/commit/78b0934dd1bb84e8f093fb8ef95ca99b297b51cd">commit</a>) - ActionView was decoupled from ActionPack and will be moved to a separated gem in Rails 4.1.</li>
<li>
<strong>Do not depend on ActiveModel</strong> (<a href="https://github.com/rails/rails/commit/166dbaa7526a96fdf046f093f25b0a134b277a68">commit</a>) - ActionPack no longer depends on ActiveModel.</li>
</ul>
<h4 id="general">3.3 General</h4>
<ul>
<li>
<strong>ActiveModel::Model</strong> (<a href="https://github.com/rails/rails/commit/3b822e91d1a6c4eab0064989bbd07aae3a6d0d08">commit</a>) - <code>ActiveModel::Model</code>, a mixin to make normal Ruby objects to work with ActionPack out of box (ex. for <code>form_for</code>)</li>
<li>
<strong>New scope API</strong> (<a href="https://github.com/rails/rails/commit/50cbc03d18c5984347965a94027879623fc44cce">commit</a>) - Scopes must always use callables.</li>
<li>
<strong>Schema cache dump</strong> (<a href="https://github.com/rails/rails/commit/5ca4fc95818047108e69e22d200e7a4a22969477">commit</a>) - To improve Rails boot time, instead of loading the schema directly from the database, load the schema from a dump file.</li>
<li>
<strong>Support for specifying transaction isolation level</strong> (<a href="https://github.com/rails/rails/commit/392eeecc11a291e406db927a18b75f41b2658253">commit</a>) - Choose whether repeatable reads or improved performance (less locking) is more important.</li>
<li>
<strong>Dalli</strong> (<a href="https://github.com/rails/rails/commit/82663306f428a5bbc90c511458432afb26d2f238">commit</a>) - Use Dalli memcache client for the memcache store.</li>
<li>
<strong>Notifications start &amp; finish</strong> (<a href="https://github.com/rails/rails/commit/f08f8750a512f741acb004d0cebe210c5f949f28">commit</a>) - Active Support instrumentation reports start and finish notifications to subscribers.</li>
<li>
<strong>Thread safe by default</strong> (<a href="https://github.com/rails/rails/commit/5d416b907864d99af55ebaa400fff217e17570cd">commit</a>) - Rails can run in threaded app servers without additional configuration.</li>
</ul>
<div class="note"><p>Check that the gems you are using are threadsafe.</p></div>
<ul>
<li>
<strong>PATCH verb</strong> (<a href="https://github.com/rails/rails/commit/eed9f2539e3ab5a68e798802f464b8e4e95e619e">commit</a>) - In Rails, PATCH replaces PUT. PATCH is used for partial updates of resources.</li>
</ul>
<h4 id="security">3.4 Security</h4>
<ul>
<li>
<strong>match do not catch all</strong> (<a href="https://github.com/rails/rails/commit/90d2802b71a6e89aedfe40564a37bd35f777e541">commit</a>) - In the routing DSL, match requires the HTTP verb or verbs to be specified.</li>
<li>
<strong>html entities escaped by default</strong> (<a href="https://github.com/rails/rails/commit/5f189f41258b83d49012ec5a0678d827327e7543">commit</a>) - Strings rendered in erb are escaped unless wrapped with <code>raw</code> or <code>html_safe</code> is called.</li>
<li>
<strong>New security headers</strong> (<a href="https://github.com/rails/rails/commit/6794e92b204572d75a07bd6413bdae6ae22d5a82">commit</a>) - Rails sends the following headers with every HTTP request: <code>X-Frame-Options</code> (prevents clickjacking by forbidding the browser from embedding the page in a frame), <code>X-XSS-Protection</code> (asks the browser to halt script injection) and <code>X-Content-Type-Options</code> (prevents the browser from opening a jpeg as an exe).</li>
</ul>
<h3 id="extraction-of-features-to-gems">4 Extraction of features to gems</h3><p>In Rails 4.0, several features have been extracted into gems. You can simply add the extracted gems to your <code>Gemfile</code> to bring the functionality back.</p>
<ul>
<li>Hash-based &amp; Dynamic finder methods (<a href="https://github.com/rails/activerecord-deprecated_finders">GitHub</a>)</li>
<li>Mass assignment protection in Active Record models (<a href="https://github.com/rails/protected_attributes">GitHub</a>, <a href="https://github.com/rails/rails/pull/7251">Pull Request</a>)</li>
<li>ActiveRecord::SessionStore (<a href="https://github.com/rails/activerecord-session_store">GitHub</a>, <a href="https://github.com/rails/rails/pull/7436">Pull Request</a>)</li>
<li>Active Record Observers (<a href="https://github.com/rails/rails-observers">GitHub</a>, <a href="https://github.com/rails/rails/commit/39e85b3b90c58449164673909a6f1893cba290b2">Commit</a>)</li>
<li>Active Resource (<a href="https://github.com/rails/activeresource">GitHub</a>, <a href="https://github.com/rails/rails/pull/572">Pull Request</a>, <a href="http://yetimedia-blog-blog.tumblr.com/post/35233051627/activeresource-is-dead-long-live-activeresource">Blog</a>)</li>
<li>Action Caching (<a href="https://github.com/rails/actionpack-action_caching">GitHub</a>, <a href="https://github.com/rails/rails/pull/7833">Pull Request</a>)</li>
<li>Page Caching (<a href="https://github.com/rails/actionpack-page_caching">GitHub</a>, <a href="https://github.com/rails/rails/pull/7833">Pull Request</a>)</li>
<li>Sprockets (<a href="https://github.com/rails/sprockets-rails">GitHub</a>)</li>
<li>Performance tests (<a href="https://github.com/rails/rails-perftest">GitHub</a>, <a href="https://github.com/rails/rails/pull/8876">Pull Request</a>)</li>
</ul>
<h3 id="documentation">5 Documentation</h3>
<ul>
<li><p>Guides are rewritten in GitHub Flavored Markdown.</p></li>
<li><p>Guides have a responsive design.</p></li>
</ul>
<h3 id="railties">6 Railties</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/railties/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="railties-notable-changes">6.1 Notable changes</h4>
<ul>
<li><p>New test locations <code>test/models</code>, <code>test/helpers</code>, <code>test/controllers</code>, and <code>test/mailers</code>. Corresponding rake tasks added as well. (<a href="https://github.com/rails/rails/pull/7878">Pull Request</a>)</p></li>
<li><p>Your app's executables now live in the <code>bin/</code> directory. Run <code>rake rails:update:bin</code> to get <code>bin/bundle</code>, <code>bin/rails</code>, and <code>bin/rake</code>.</p></li>
<li><p>Threadsafe on by default</p></li>
<li><p>Ability to use a custom builder by passing <code>--builder</code> (or <code>-b</code>) to
<code>rails new</code> has been removed. Consider using application templates
instead. (<a href="https://github.com/rails/rails/pull/9401">Pull Request</a>)</p></li>
</ul>
<h4 id="railties-deprecations">6.2 Deprecations</h4>
<ul>
<li><p><code>config.threadsafe!</code> is deprecated in favor of <code>config.eager_load</code> which provides a more fine grained control on what is eager loaded.</p></li>
<li><p><code>Rails::Plugin</code> has gone. Instead of adding plugins to <code>vendor/plugins</code> use gems or bundler with path or git dependencies.</p></li>
</ul>
<h3 id="action-mailer">7 Action Mailer</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="action-mailer-notable-changes">7.1 Notable changes</h4><h4 id="action-mailer-deprecations">7.2 Deprecations</h4><h3 id="active-model">8 Active Model</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activemodel/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="active-model-notable-changes">8.1 Notable changes</h4>
<ul>
<li><p>Add <code>ActiveModel::ForbiddenAttributesProtection</code>, a simple module to protect attributes from mass assignment when non-permitted attributes are passed.</p></li>
<li><p>Added <code>ActiveModel::Model</code>, a mixin to make Ruby objects work with Action Pack out of box.</p></li>
</ul>
<h4 id="active-model-deprecations">8.2 Deprecations</h4><h3 id="active-support">9 Active Support</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activesupport/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="active-support-notable-changes">9.1 Notable changes</h4>
<ul>
<li><p>Replace deprecated <code>memcache-client</code> gem with <code>dalli</code> in <code>ActiveSupport::Cache::MemCacheStore</code>.</p></li>
<li><p>Optimize <code>ActiveSupport::Cache::Entry</code> to reduce memory and processing overhead.</p></li>
<li><p>Inflections can now be defined per locale. <code>singularize</code> and <code>pluralize</code> accept locale as an extra argument.</p></li>
<li><p><code>Object#try</code> will now return nil instead of raise a NoMethodError if the receiving object does not implement the method, but you can still get the old behavior by using the new <code>Object#try!</code>.</p></li>
<li><p><code>String#to_date</code> now raises <code>ArgumentError: invalid date</code> instead of <code>NoMethodError: undefined method 'div' for nil:NilClass</code>
when given an invalid date. It is now the same as <code>Date.parse</code>, and it accepts more invalid dates than 3.x, such as:</p></li>
</ul>
<div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
  # ActiveSupport 3.x
  "asdf".to_date # =&gt; NoMethodError: undefined method `div' for nil:NilClass
  "333".to_date # =&gt; NoMethodError: undefined method `div' for nil:NilClass

  # ActiveSupport 4
  "asdf".to_date # =&gt; ArgumentError: invalid date
  "333".to_date # =&gt; Fri, 29 Nov 2013

</pre>
</div>
<h4 id="active-support-deprecations">9.2 Deprecations</h4>
<ul>
<li><p>Deprecate <code>ActiveSupport::TestCase#pending</code> method, use <code>skip</code> from MiniTest instead.</p></li>
<li><p><code>ActiveSupport::Benchmarkable#silence</code> has been deprecated due to its lack of thread safety. It will be removed without replacement in Rails 4.1.</p></li>
<li><p><code>ActiveSupport::JSON::Variable</code> is deprecated. Define your own <code>#as_json</code> and <code>#encode_json</code> methods for custom JSON string literals.</p></li>
<li><p>Deprecates the compatibility method <code>Module#local_constant_names</code>, use <code>Module#local_constants</code> instead (which returns symbols).</p></li>
<li><p><code>BufferedLogger</code> is deprecated. Use <code>ActiveSupport::Logger</code>, or the logger from Ruby standard library.</p></li>
<li><p>Deprecate <code>assert_present</code> and <code>assert_blank</code> in favor of <code>assert object.blank?</code> and <code>assert object.present?</code></p></li>
</ul>
<h3 id="action-pack">10 Action Pack</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/actionpack/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="action-pack-notable-changes">10.1 Notable changes</h4>
<ul>
<li>Change the stylesheet of exception pages for development mode. Additionally display also the line of code and fragment that raised the exception in all exceptions pages.</li>
</ul>
<h4 id="action-pack-deprecations">10.2 Deprecations</h4><h3 id="active-record">11 Active Record</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="active-record-notable-changes">11.1 Notable changes</h4>
<ul>
<li>
<p>Improve ways to write <code>change</code> migrations, making the old <code>up</code> &amp; <code>down</code> methods no longer necessary.</p>
<ul>
<li>The methods <code>drop_table</code> and <code>remove_column</code> are now reversible, as long as the necessary information is given.
The method <code>remove_column</code> used to accept multiple column names; instead use <code>remove_columns</code> (which is not revertible).
The method <code>change_table</code> is also reversible, as long as its block doesn't call <code>remove</code>, <code>change</code> or <code>change_default</code>
</li>
<li>New method <code>reversible</code> makes it possible to specify code to be run when migrating up or down.
See the <a href="https://github.com/rails/rails/blob/master/guides/source/active_record_migrations.md#using-reversible">Guide on Migration</a>
</li>
<li>New method <code>revert</code> will revert a whole migration or the given block.
If migrating down, the given migration / block is run normally.
See the <a href="https://github.com/rails/rails/blob/master/guides/source/active_record_migrations.md#reverting-previous-migrations">Guide on Migration</a>
</li>
</ul>
</li>
<li><p>Adds PostgreSQL array type support. Any datatype can be used to create an array column, with full migration and schema dumper support.</p></li>
<li><p>Add <code>Relation#load</code> to explicitly load the record and return <code>self</code>.</p></li>
<li><p><code>Model.all</code> now returns an <code>ActiveRecord::Relation</code>, rather than an array of records. Use <code>Relation#to_a</code> if you really want an array. In some specific cases, this may cause breakage when upgrading.</p></li>
<li><p>Added <code>ActiveRecord::Migration.check_pending!</code> that raises an error if migrations are pending.</p></li>
<li>
<p>Added custom coders support for <code>ActiveRecord::Store</code>. Now you can set your custom coder like this:</p>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
store :settings, accessors: [ :color, :homepage ], coder: JSON

</pre>
</div>
</li>
<li><p><code>mysql</code> and <code>mysql2</code> connections will set <code>SQL_MODE=STRICT_ALL_TABLES</code> by default to avoid silent data loss. This can be disabled by specifying <code>strict: false</code> in your <code>database.yml</code>.</p></li>
<li><p>Remove IdentityMap.</p></li>
<li><p>Remove automatic execution of EXPLAIN queries. The option <code>active_record.auto_explain_threshold_in_seconds</code> is no longer used and should be removed.</p></li>
<li><p>Adds <code>ActiveRecord::NullRelation</code> and <code>ActiveRecord::Relation#none</code> implementing the null object pattern for the Relation class.</p></li>
<li><p>Added <code>create_join_table</code> migration helper to create HABTM join tables.</p></li>
<li><p>Allows PostgreSQL hstore records to be created.</p></li>
</ul>
<h4 id="active-record-deprecations">11.2 Deprecations</h4>
<ul>
<li><p>Deprecated the old-style hash based finder API. This means that methods which previously accepted "finder options" no longer do.</p></li>
<li>
<p>All dynamic methods except for <code>find_by_...</code> and <code>find_by_...!</code> are deprecated. Here's
how you can rewrite the code:</p>
<ul>
<li>
<code>find_all_by_...</code> can be rewritten using <code>where(...)</code>.</li>
<li>
<code>find_last_by_...</code> can be rewritten using <code>where(...).last</code>.</li>
<li>
<code>scoped_by_...</code> can be rewritten using <code>where(...)</code>.</li>
<li>
<code>find_or_initialize_by_...</code> can be rewritten using <code>find_or_initialize_by(...)</code>.</li>
<li>
<code>find_or_create_by_...</code> can be rewritten using <code>find_or_create_by(...)</code>.</li>
<li>
<code>find_or_create_by_...!</code> can be rewritten using <code>find_or_create_by!(...)</code>.</li>
</ul>
</li>
</ul>
<h3 id="credits">12 Credits</h3><p>See the <a href="http://contributors.rubyonrails.org/">full list of contributors to Rails</a> for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.</p>

        <h3>反馈</h3>
        <p>
          我们鼓励您帮助提高本指南的质量。
        </p>
        <p>
          如果看到如何错字或错误，请反馈给我们。
          您可以阅读我们的<a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">文档贡献</a>指南。
        </p>
        <p>
          您还可能会发现内容不完整或不是最新版本。
          请添加缺失文档到 master 分支。请先确认 <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> 是否已经修复。
          关于用语约定，请查看<a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails 指南指导</a>。
        </p>
        <p>
          无论什么原因，如果你发现了问题但无法修补它，请<a href="https://github.com/rails/rails/issues">创建 issue</a>。
        </p>
        <p>
          最后，欢迎到 <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs 邮件列表</a>参与任何有关 Ruby on Rails 文档的讨论。
        </p>
        <h4>中文翻译反馈</h4>
        <p>贡献：<a href="https://github.com/ruby-china/guides">https://github.com/ruby-china/guides</a>。</p>
      </div>
    </div>
  </div>

  <hr class="hide" />
  <div id="footer">
    <div class="wrapper">
      <p>本著作采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/">创作共用 署名-相同方式共享 4.0 国际</a> 授权</p>
<p>“Rails”，“Ruby on Rails”，以及 Rails Logo 为 David Heinemeier Hansson 的商标。版权所有</p>

    </div>
  </div>

  <script type="text/javascript" src="javascripts/jquery.min.js"></script>
  <script type="text/javascript" src="javascripts/responsive-tables.js"></script>
  <script type="text/javascript" src="javascripts/guides.js"></script>
  <script type="text/javascript" src="javascripts/syntaxhighlighter.js"></script>
  <script type="text/javascript">
    syntaxhighlighterConfig = {
      autoLinks: false,
    };
    $(guidesIndex.bind);
  </script>
</body>
</html>
